home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / chmod.c < prev    next >
C/C++ Source or Header  |  1994-03-01  |  1KB  |  63 lines

  1. /* chmod -- change the permissions of a file */
  2. /* written by Eric R. Smith and placed in the public domain */
  3.  
  4. #include <types.h>
  5. #include <stat.h>
  6. #include <osbind.h>
  7. #include <mintbind.h>
  8. #include <limits.h>
  9. #include <errno.h>
  10. #include <unistd.h>
  11. #include "lib.h"
  12.  
  13. extern int __mint;
  14.  
  15. int
  16. chmod(_path, mode)
  17.        const char *_path;
  18.        int   mode;
  19. {
  20.        int  dosattrib = 0, r;
  21.        char path[PATH_MAX];
  22.  
  23.        (void)_unx2dos(_path, path);
  24.  
  25.     if (__mint >= 9) {    /* use MiNT Fchmod function */
  26.         r = (int)Fchmod(path, mode);
  27.         if (r) {
  28.             errno = -r;
  29.             return -1;
  30.         }
  31.         return 0;
  32.     }
  33.  
  34. /* The following lines ensure that the archive bit isn't cleared */
  35.     r = Fattrib(path, 0, 0);
  36.     if (r < 0)
  37.       {
  38.         errno = -r;
  39.         return -1;
  40.       }
  41.      if (r & FA_CHANGED)
  42.         dosattrib |= FA_CHANGED;
  43.  
  44.     if (r & FA_DIR)
  45.       dosattrib |= FA_DIR;
  46. #if 0
  47.        if (!(mode & S_IREAD))
  48.                dosattrib |= FA_HIDDEN;
  49. #endif
  50.        if (!(mode & S_IWRITE))
  51.                dosattrib |= FA_RDONLY;
  52.        r = Fattrib(path, 1, dosattrib);
  53.        if (r < 0) {
  54. /* GEMDOS doesn't allow chmod on a directory, so pretend it worked */
  55.         if (dosattrib & FA_DIR)
  56.           return 0;
  57.                errno = -r;
  58.                return -1;
  59.        }
  60.        return 0;
  61. }
  62.  
  63.